﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cocos2d;

namespace RunCircle
{
    class TrapBoard : Trap
    {
        List<CCSpriteFrame> m_AnimFrames;
        public TrapBoard()
        {
            m_TrapType = "Trap_Board";

            m_AnimFrames = new List<CCSpriteFrame>();
            string framename01 = "careful.png";
            CCSpriteFrame spriteframe_01 = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(framename01);
            m_AnimFrames.Add(spriteframe_01);

            initWithSpriteFrameName(framename01);
            CCSpriteFrame frame = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(framename01);
            this.width = frame.Rect.size.width;
            height = frame.Rect.size.height;

            playAnimation();
        }

        public override void setRotateByPoint(CCPoint playerpos, CCPoint anchopos, float rot, CCPoint rotateBy)
        {
            this.position = playerpos;

            if (width > 0.0f && height > 0.0f)
            {
                anchopos.y = anchopos.y - height/2.0f;
                float ax = 0.5f - (rotateBy.x - anchopos.x) / width;
                float ay = 0.5f - (rotateBy.y - anchopos.y) / height;
                this.anchorPoint = new CCPoint(ax, ay);
            }
            else
            {
                //有问题;
            }

            this.rotation = rot;
        }

        private void playAnimation()
        {
            CCAnimation ani = CCAnimation.animationWithFrames(m_AnimFrames);
            CCAnimate animaction = CCAnimate.actionWithDuration(1.0f, ani, true);
            this.runAction(CCRepeatForever.actionWithAction(animaction));
        }

        public override void update(float dt)
        {
            base.update(dt);
        }

        public override bool checkCollision()
        {
            return false;
        }
    }
}
